package com.aijk.web.admin.utils;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.apache.commons.httpclient.params.HttpMethodParams;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class RequestUtil {
	private static String hcc = HttpMethodParams.HTTP_CONTENT_CHARSET;



	public static String getTijianData() {
		String pinyinUsername = "";
//        String connUrl = Config.getConfig().get("requestPinyinUsernameUrl");
		String connUrl = "http://10.10.0.39:80/report?CheckupID=17021400002";

		try {
            /*username = URLEncoder.encode(username, "utf-8");
            URL url = new URL(connUrl + "?name=" + username + "&type=" + usernametype);*/
			URL url = new URL(connUrl);
			HttpURLConnection conn = (HttpURLConnection) url.openConnection();
			conn.setRequestMethod("POST");

			//设置访问提交模式，表单提交
			conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
			conn.setConnectTimeout(20000);//连接超时 单位毫秒
			conn.setReadTimeout(30000);//读取超时 单位毫秒
//            conn.setRequestProperty("timestamp", "1498719549095");
			conn.setRequestProperty("timestamp", "1503457589427");
			conn.setRequestProperty("openId", "yijia");
			conn.setRequestProperty("type", "2");
//            conn.setRequestProperty("sign", "rKIUOv2JuYpd2Gsu1sLFE0G4hql+F7T2");
			conn.setRequestProperty("sign", "zwZGcRGpA8sThtYKmfwkYkG4hql+F7T2");
			conn.setRequestProperty("encrypt", "0");

			//读取请求返回值
			BufferedReader responseBuffer = new BufferedReader(new InputStreamReader((conn.getInputStream())));
			String output = "";
			while ((output = responseBuffer.readLine()) != null) {
				pinyinUsername = pinyinUsername + output;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		return pinyinUsername;
	}

	public static void main(String[] args) {

//		String result = getTijianData();
//		System.out.println(result);

	}

}
